<template>
  <div class='identify'>
    <IdentifyHead @submit="submit" :hiddenbtn="progressIndex>1" />
    <main>
      <div class="progress-box">
        <el-steps :active="progressIndex" align-center>
          <el-step title="提交申请" description=""></el-step>
          <el-step title="资质审核" description=""></el-step>
          <el-step title="完成" description=""></el-step>
        </el-steps>
      </div>
      <div class="input-box ft16">
        <div v-for="(item, index) in modelData" :key="index" class="mb15">
          <span class="title">{{item.label}}：</span>
          <span v-if="item.islabel">{{info[item.prop]}}</span>
          <span v-else-if="item.isword" class="color-blue hover" @click="showPic(item)">查看照片</span>
          <ComAddress v-else-if="item.isAddress" @handleAddress="handleAddress" :prop="item.prop" :defaultV="info[item.prop]" :isreadonly="progressIndex!=1" />
          <UploadImg v-else-if="item.isupload"  :isreadonly="progressIndex!=1" @success="success" :keys="item.prop" :defaultImg0="info[item.prop]" />
          <el-input :readonly="progressIndex!=1" v-else :placeholder="item.placeholder" v-model="info[item.prop]"></el-input>
        </div>
      </div>
    </main>
  </div>
</template>
<script>
import IdentifyHead from '../../buyer/specify/detail/head.vue'
import ComAddress from '@/components/address.vue'
import UploadImg from '@/components/upload/uploadImg.vue'
export default {
  components: {IdentifyHead,ComAddress,UploadImg},
  name: "",
  data() {
    return {
      progressIndex:1,//进度 1 提交
      modelData:[
        {prop:"companyName",label:"公司名称",islabel:false,placeholder:"请输入完整公司名称（与营业执照保持一致）",checked:true},
        {prop:"companyPhone",label:"公司电话",placeholder:"请输入座机号码",checked:true},
        {prop:"address",label:"公司地址",isAddress:true,checked:true},
        {prop:"addressInfo",label:"详细地址",placeholder:"请输入详细地址",checked:true},
        {prop:"legalPerson",label:"企业法人",placeholder:"请输入企业法人",checked:true},
        {prop:"phone",label:"手机号",placeholder:"请输入手机号",checked:true},
        {prop:"dutyNum",label:"税号",placeholder:"请输入税号",checked:true},
        {prop:"authorization",label:"企业认证授权书",isupload:true,checked:true,isword:true,},
        {prop:"licence",label:"开户许可证",isupload:true,checked:true,isword:true,},
        {prop:"permit",label:"营业执照",isupload:true,checked:true,isword:true,},
      ],
      info:{
        companyName:"",
        companyPhone:"",
        address:"",
        addressInfo:"",
        legalPerson:"",
        phone:"",
        dutyNum:"",
        authorization:"",
        licence:"",
        permit:"",
      }
    };
  },
  methods: {
    init(){
      _g.apiPost('iuser/companyCertInfo.do').then(res=>{
        if(!res.data){
          this.progressIndex=1
        }else if(res.data.status==0){
            this.progressIndex=2
            this.modelData.forEach(ele=>{
                if(!ele.isupload){
                    ele.islabel=true
                }else{
                    ele.isword=true
                }
            })
            this.info=res.data
        }else if(res.data.status==1){
          _g.toMessage({status:res.data.status==1?1:0,msg:res.data.status==1?'审核不通过':'审核通过'})
          this.progressIndex=res.data.status==1?1:3
        }else if(res.data.status==2){
            this.progressIndex=3
            this.modelData.forEach(ele=>{
                if(!ele.isupload){
                    ele.islabel=true
                }else{
                    ele.isword=true
                }
            })
            this.info=res.data

        }
      })
    },

    /**
     # name 修改地址
     # description 接受地址组件传过来的 
     */
    handleAddress(val){
      this.info[val.key]=val.value
    },

    /**
     * # 上传回调
     */
    success(val){
      this.info[val.key]=val.data
    },
    showPic(item){
      this.$set(item,"isword",false)
      console.log(item)
    },
    /**
     * @name 提交
     */
    submit(){
      let params = this.info
      params.address=params.address.join('/')
      if(_g.checkParams(this.modelData,this.info))return
      _g.apiPost('iuser/addCompanyCert.do',params,true).then(res=>{
        _g.toMessage(res)
        if(res.status==0){
          this.progressIndex=2
        }
      })
    }
  },
  created() {
    this.init()
  }
};
</script>
<style lang="scss" scoped>
.identify {

  main{
    min-height: 600px;
    padding: 50px;
  }
  .input-box{
    width: 55%;
    margin: 50px auto;

    >div{
      display: flex;

      span{
        line-height: 40px;
      }
      .title{
        display: inline-block;
        min-width: 140px;
        line-height: 40px;
        text-align: right;
      }
      .el-input{
        width: 350px;
      }
    }
  }
}
</style>